<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <script src="/layui/layui.js"></script>
  <script src="/js/jquery/jquery-3.5.1.js"></script>
  <script src="/js/book/book.js"></script>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/bookList.css">
  <link rel="stylesheet" href="/component/pear/css/pear.css" />
  <script src="/component/pear/pear.js"></script>
  <script src="/js/book/bookCommon.js"></script>
  <title>数据管理</title>
</head>
<body>
<div class="book-title  " id = "book-title"></div>
<div class="book-list" id="book-list" width="100%" >
  <table class="table-book" id="table-book" >
  </table>
</div>

<script type="text/javascript"  th:inline="javascript">
  debugger
  var downFile;
  var data = JSON.stringify([[${data}]]);
  data = $.parseJSON( data );
  document.title=$.parseJSON( data ).bookName;
  var chapterInfo="";
  $.ajax({
    type:"post",
    url:'/bookMagic/getBookInfo',
    data:data,
    dataType:"json",
    async:false,
    contentType : "application/json; charset=utf-8",
    success: function(res){
      var book = res.data;
      var zjList = book.chapterInfo;
      var btitle = book.bookInfo;
      document.title=btitle.bookName;
      downFile = btitle;
      var div="";
      div="<div class='table-css'> " +
              "<div class='maininfo'>" +
              "<div class='info'>" +
              "<h1>"+btitle.bookName+"</h1>" +
              "<p>作者："+btitle.bookAuthor+"</p>" +
              "<p>状态："+btitle.bookState+"<a style='padding-left: 10px' onclick='downBookFile("+data+")'>txt下载</a></p>"+
              "<p>最后更新:"+btitle.bookLastChapterDate+"</p>"+
              "<p>最新章节: <a onclick='newChapterContextfowdard("+JSON.stringify(btitle)+")'>"+btitle.bookLastChapter+"</a></p>"+
              "</div>" +
              "<div class='intro'>"+btitle.bookDuce+"</div>"+

              "</div>"+
              "<div class='sidebar'>" +
              "<div class='fmimg'>" +
              "<img src="+btitle.bookCover+" onerror=\"javascript:this.src='/img/magic/nocover.jpg';this.onerror = null\" alt="+btitle.bookName+" width='120' height='150'>" +
              "</div>" +
              "</div>"+
              "</div>"
      $("#book-title").append(div);

      var num = zjList.length/3;
      var dd="";
      for(var i = 0; i < zjList.length; i++ ){
        var detail =  zjList[i] ;
        dd += "<dd>" +
                "<a  onclick='chapterContextfowdard("+JSON.stringify(detail)+")' target='_blank'>"+detail.chapterName+"</a>" +
                "</dd>"
      }
      var div="";
      div="<div class='chapter_list'> "+
              "<dl>" +
              "<dt class='b_list'>  "+'《'+btitle.bookName+'》'+"</dt>" +dd+
              "</dl>"+
              "</div>"
      $("#table-book").append(div);
      $("#downLoad").on("click", function () {
        layui.use('layer', function(){
          var layer = layui.layer;
          layer.msg(' '+bookName+'', {
            shadeClose: true,
            time:0,
            title: false,
            closeBtn: 0,
            area: ['300px', '150px'],
            btn: ['下载']
          },  function(){
            window.open("/book/downloadBook?bookCode="+bookCode+"&bookName="+bookName+"");
          });

        });
      });
    }
  });
  function chapterContextfowdard(obj){
    debugger
     obj.bookUrl =$.parseJSON( data ).bookUrl;
     chapterInfo = obj;
    forward('/forward/book/pageBook/bookRead',chapterInfo,"_self")
  }
  function newChapterContextfowdard(obj){
    obj.chapterUrl =$.parseJSON( data ).bookLastChapterUrl;

    forward("/forward/book/pageBook/bookRead",obj,"_self");
  }
  function downBookFile(obj){
      downLoadFile("/bookMagic/downloadFile/",downFile)
/*
    //墨绿深蓝风
    var layer;
    layui.use('element', function () {
      var element = layui.element;
      var layui_element = layui.element,
              layui_layer = layui.layer,
              layui_form = layui.form;
    });
    layui.use('layer', function () {
      layer = layui.layer;
      layer.msg('hello');
    });*/
  }
</script>

</body>
</html>